﻿Public Partial Class Usuario
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Util.EhVazioNull(Session("IdUsuario")) Then
            Response.Redirect("Login.aspx")
        End If
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        If VerificaSeTrocaSenha() Then
            Dim ta As DataSet1TableAdapters.UsuarioTableAdapter = New DataSet1TableAdapters.UsuarioTableAdapter
            Dim table As DataSet1.UsuarioDataTable
            table = ta.GetDataByIdUsuario(Session("IdUsuario"))
            table.Rows(0).Item("Senha") = txtSenha.Text.GetHashCode
            ta.Update(table.Rows(0).Item("Login"), table.Rows(0).Item("Senha"), table.Rows(0).Item("IdUsuario"))
            Response.Redirect("Home.aspx")
        End If
    End Sub

    Private Function VerificaSeTrocaSenha()
        Dim ta As DataSet1TableAdapters.UsuarioTableAdapter = New DataSet1TableAdapters.UsuarioTableAdapter
        Dim table As DataSet1.UsuarioDataTable
        table = ta.GetDataByIdUsuario(Session("IdUsuario"))
        Dim SenhaBanco As String = ""
        If table.Rows.Count > 0 Then
            SenhaBanco = table.Rows(0).Item("Senha")
        Else
            Response.Write("RODNEI COUTO")
        End If
        If txtSenhaAntiga.Text.GetHashCode = SenhaBanco Then
            If txtSenha.Text = txtSenhaRepetida.Text Then
                Return True
            Else
                Response.Write("RODNEI COUTO")
            End If
        End If
        Return False
    End Function

End Class